package com.atguigu.service.vod.controller;

import com.atguigu.guli.service.base.result.R;
import com.atguigu.service.vod.service.impl.MediaServiceImpl;
import com.mysql.cj.x.protobuf.Mysqlx;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@Api(tags = "视频上传")
@RestController
@RequestMapping("/admin/vod/media")
public class VodController {

    @Autowired
    MediaServiceImpl mediaService;
    //上传视频
    @ApiOperation("上传视频")
    @PostMapping("/uplod")
    public R uplodVod(@RequestParam("file")MultipartFile file){
        String upload = mediaService.upload(file);
        return R.ok().data("data",upload);
    }
    //获取未加密视频地址
    @ApiOperation("获取未加密的视频地址")
    @GetMapping("/url/{videoId}")
    public R getUrl(@PathVariable String videoId){
        String playUrl = mediaService.getPlayUrl(videoId);
        return R.ok().data("data",playUrl);
    }

    //获取加密视频凭证
    @ApiOperation("获取加密的视频凭证")
    @GetMapping("/getPlayAuth/{videoId}")
    public R getPlayAuth(@PathVariable String videoId){
        String playUrl = mediaService.getPlayAuth(videoId);
        return R.ok().data("data",playUrl);
    }
}

